package com.test.demo1.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.test.demo1.entity.Student;
import com.test.demo1.service.StudentService;
import com.test.demo1.util.Result;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.annotation.Resource;

/**
 * 
 * @author huishao
 * @since 2022-11-10 18:01:15
 */
@RestController
@RequestMapping("student")
public class StudentController {
    /**
     * 注入 StudentController 服务对象
     */
    @Resource
    private StudentService studentService;
    
    @GetMapping("/{page}/{limit}")
    public Result listByPage(@PathVariable("page") Long page, @PathVariable("limit") Long limit){
        return Result.ok((studentService).page(new Page<>(page,limit)).getRecords());
    }
    
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") String id){
        return Result.ok((studentService).getById(id));
    }

    @PostMapping()
    public Result insert(@RequestBody Student student){
        if (student == null) {
            return Result.fail();
        }
        return Result.ok((studentService).save(student));
    }
        
    @PutMapping()
    public Result update(@RequestBody Student student){
        if (student == null) {
            return Result.fail();
        }
        return Result.ok((studentService).update(student));
    }
    
    
    // 删除方法自己写 ！ 


}

